package LeetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}17:36
 */
public class E4 {//替换字符串中的空格
    public static void main(String[] args) {
        String s = "    ";
        System.out.println(replaceSpace(s));
    }

    public static String replaceSpace(String s) {
//        String[] strings = s.split(" ");
//        String string ="";
//        for (int i = 0; i < strings.length; i++){
//            if (i == strings.length-1){
//                string += strings[i];
//                continue;
//            }
////            stringBuilder.append(strings[i]+"%20");
//            string += strings[i] +"%20";
//        }
//        return string;
        List<String> list = new ArrayList<>();
        char[] chars = s.toCharArray();
        for (char index:chars){
            if (index == ' '){
                list.add("%20");
            }else {
                list.add(String.valueOf(index));
            }
        }
        String s1 = "";
        for (String s2:list){
            s1+=s2;
        }
        return s1;
    }
}
